<?php
namespace app\backstage\validate;
use think\Validate;

class Baidu extends Validate
{
    protected $rule = [
        'id'                    => 'require|gt:0',
        'accountname'                    => 'require',
        'akey'                    => 'require',

    ];

    protected $message  =   [
        'id.require'                    => '账户编号不能为空',
        'id.gt'                         => '账户编号不能为空',
        'accountname.require'            => '请填写账户名',
        'akey.require'            => '请填写账户akey',
    ];

    protected $scene = [
        'add'       => ['accountname','akey'],
        'info'      => ['id'],
    ];

    // 自定义验证规则
    protected function checkIds($value, $rule, $data = [])
    {
        if (!preg_match('#^[1-9][0-9]*(,[1-9][0-9]*)*$#', $value)) {
            return '参数异常';
        }
        return true;
    }
}